//
// Created by xyx16 on 2025/8/4.
//
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

class Solution {
public:
    vector<vector<int>> threeSum(vector<int>& nums) {
        int n = nums.size();
        vector<vector<int>> res;
        for (int i = 0; i < n; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                for (int k = j + 1; k < n; k++)
                {
                    if (nums[i] + nums[j] + nums[k] == 0)
                    {
                        vector<int> temp = {nums[i], nums[j], nums[k]};

                        sort(temp.begin(), temp.end());
                        bool flag = false;
                        for (vector<int> m:res)
                        {
                            if (m[0] == temp[0] && m[1] == temp[1] && m[2] == temp[2])
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            res.push_back(temp);
                        }

                    }
                }
            }
        }
        return res;

    }
};

int main()
{
    Solution s;
    vector<int> nums = {-1, 0, 1, 2, -1, -4};
    vector<vector<int> > result = s.threeSum(nums);
    for (vector<int> v : result)
    {
        for (int i : v)
        {
            cout << i << " ";
        }
        cout << endl;
    }
}